<?php
/**
 * Created by JetBrains PhpStorm.
 * User: zhouyang
 * Date: 13-9-6
 * Time: 下午4:31
 * To change this template use File | Settings | File Templates.
 */
class NewsDB  extends DBReader{

    //根据new_id 获取new 信息
    public function get($new_id){

        $sql = 'select new_id, category_id, source_id, title, keywords, description, status, summary, published, update_time, content, tag, picture, user_id from news where new_id = :new_id';

        return $this->db()->getRow($sql,array('new_id'=>$new_id));
    }

    //获取cate 列表<带分页>
    public function getNewListByCategoryId($curr_page,$per_page,$filter = array()){
        $where = ' 1=1 ';
        $bindarr = array();

        if(isset($filter['category_id'])){
            $where .= ' and category_id = :category_id';
            $bindarr['category_id'] = $filter['category_id'];
        }

        $where .= ' and status >= :status';
        $bindarr['status'] = 3;

        $ret = $this->pager($curr_page, $per_page)
            ->ct('select count(new_id) from news where ' . $where , $bindarr)
            ->rs('select new_id, category_id, source_id, title, status, summary, update_time, char_length(content) as content_len, picture, user_id from news where '.$where.' order by published desc',$bindarr);

        return $ret;
    }

    //获取首页推荐的最新3条数据
    public function getRecommendIndexList(){

        $sql = 'select new_id,title,picture from news where status = 5 order by published desc';

        return $this->db()->selectLimit($sql,3);
    }

    //批量获取资讯信息
    public function mulitGetNewInfo($new_ids){

        $sql = 'select new_id, category_id, source_id, title, keywords, description, status, summary, published, update_time, content, tag, picture, user_id from news where new_id in('.$new_ids.')';

        return $this->db()->getAll($sql);
    }
}